import type { Request, ResponseToolkit } from "@hapi/hapi";
import Hapi from "@hapi/hapi";
import { Routes } from "../../model/index";

let route: Hapi.ServerRoute<Hapi.ReqRefDefaults> = {
  path: "/addMenu",
  method: "post",
  handler: async (r: Request, h: ResponseToolkit) => {
    try {
      let list = await new Routes(r.payload);
      await list.save();
      return {
        code: 200,
        data: null,
        message: "添加成功",
      };
    } catch (err: any) {
      return err;
    }
  },
  options: {
    payload: {
      parse: true, // 解析请求体
      allow: "application/json", // 允许JSON格式的请求体
    },
    plugins: {
      "hapi-swagger": {
        security: [{ apiKey: [] }],
      },
    },
    tags: ["api"],
  },
};
export default route;
